def check(a):
    count = 0
    for i in range(2, int(int(a)**0.5 + 1)):
        if int(a) % i == 0:
            count += 1
    if count == 0 and int(a) != 1:
       numbers.append(int(a))


x = input()
numbers = []
a = x
check(a)
for i in range(len(x)):
    a = x[i]
    check(a)
for i in range(2, len(x) + 1):
    a = x[0 if i == 2 else 1 if i == 3 else 2:i]
    check(a)
for i in range(3, len(x) + 1):
    a = x[0 if i == 3 else 1:i]
    check(a)
print(max(numbers) if numbers != [] and 999 < int(x) < 10000 else 0)